package com.ryskoo.basicdata.organization.service;

import com.ryskoo.basicdata.organization.domain.OrganizationPO;
import com.ryskoo.basicdata.organization.repository.IOrganizationRepository;
import com.ryskoo.framework.core.service.BasicServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 组织机构业务处理层
 * @author thq
 */
@Service
public class OrganizationServiceImpl extends BasicServiceImpl<OrganizationPO> implements IOrganizationService {
    @Autowired
    private IOrganizationRepository organizationRepository;

    @PostConstruct
    public void init() {
        this.setDao(organizationRepository);
    }


	/**
	 * 获取组织机构列表
	 * 树状结构的列表，子组织也会获取
	 * @param parentId
	 *  @return 
	 */
	@Override
	public List<OrganizationPO> getByParentId(String parentId) {
		//获取一级组织机构
		List<OrganizationPO> list = organizationRepository.getByParentId(parentId);
		if (list != null && list.size() >0) {
			for (OrganizationPO organizationPO : list) {
				List<OrganizationPO> childrenList = organizationRepository.getByParentId(organizationPO.getUuid());
				organizationPO.setChildrens(childrenList);
			}
		}
		return list;
	}
}
